import { Prefab, resources } from "cc";
import { Ab_GameSetting_bA } from "./popup.game.setting";
import { Ab_GameVictory_bA } from "./popup.game.victory";

export enum Ab_EGamePopup_bA {
	Ab_SETTING_bA,
	Ab_VICTORY_bA,
}

const Ab_CONFIG_bA = {
	[Ab_EGamePopup_bA.Ab_SETTING_bA]: {
		component: Ab_GameSetting_bA,
		path: 'prefab-game/pop-up/setting',
		script: './popup.game.setting.ts',
		prefab: null
	},
	[Ab_EGamePopup_bA.Ab_VICTORY_bA]: {
		component: Ab_GameVictory_bA,
		path: 'prefab-game/pop-up/victory',
		script: './popup.game.victory.ts',
		prefab: null
	},
}

export async function Ab_GetGamePopPrefab_bA(p: Ab_EGamePopup_bA): Promise<Prefab> {
	let conf = Ab_CONFIG_bA[p];
	if(!conf.prefab){
		conf.prefab = await abi.Ab_cc_bA.Ab_loadResAsync_bA(conf.path, Prefab, resources);
	}

	return conf.prefab;
}

export async function Ab_GetGamePopComponent_bA<P extends Ab_EGamePopup_bA>(p: P): Promise<(typeof Ab_CONFIG_bA)[P]['component']> {
	let conf = Ab_CONFIG_bA[p];
	if(!conf.component){
		conf.component = await import(conf.script).then(m=>m.default);
	}

	return conf.component;
}

export type Ab_GamePopCtor_bA<P extends Ab_EGamePopup_bA> = typeof Ab_CONFIG_bA[P]['component'];

export type Ab_GamePopIns_bA<P extends Ab_EGamePopup_bA> = InstanceType<Ab_GamePopCtor_bA<P>>;

export type Ab_GamePopParams_bA<P extends Ab_EGamePopup_bA> = Parameters<Ab_GamePopIns_bA<P>['Ab_onShow_bA']>;

export type Ab_GamePopReturn_bA<P extends Ab_EGamePopup_bA> = Awaited<ReturnType<Ab_GamePopIns_bA<P>['Ab_show_bA']>>;